<?php

namespace App\Services\Common;

use App\Services\Contracts\ServiceInterface;

abstract class Service implements ServiceInterface
{
    /**
     * @var
     */
    protected $repository;

    /**
     * Service constructor.
     */
    public function __construct()
    {
        $this->repository = $this->repository();
    }

    /**
     * @return mixed
     */
    abstract public function repository();

    /**
     * @return mixed
     */
    public function all()
    {
        return $this->repository->all();
    }

    /**
     * @param $id
     * @return mixed
     */
    public function getById($id)
    {
        return $this->repository->find($id);
    }

    /**
     * @param array $data
     * @return mixed
     */
    public function store(array $data)
    {
        return $this->repository->create($data);
    }

    /**
     * @param array $data
     * @param $id
     * @return mixed
     */
    public function update(array $data, $id)
    {
        return $this->repository->updateById($data, $id);
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->repository->delete($id);
    }

}